/**
 *
 */
define(['jquery', 'fileUtil', 'jquery-validate-messages_zh'], function ($, FileUtil, Validate) {
    'use strict';

    var Page = {}, DOM;

    function init() {
        DOM = {
            form: $('#form'),
            btnSubmit: $('#btnSubmit'),
            file: $('#file'),
            downloadFile: $('#downloadFile')
        }
    }

    Page.main = function () {
        init();
        handleEvent();
    };

    function handleEvent() {
        // 表单校验
        DOM.form.validate({
            rules: {
                display: {
                    required: true
                },
                top: {
                    required: true
                },
                fileClassId: {
                    required: true
                }
            },
        });

        // 提交表单
        DOM.btnSubmit.click(function () {
            var file = $("#file").get(0).files[0];
            var data;
            FileUtil.upload(file, function (rs) {
                data = rs;
            });
            console.log('data=' + data);
            if (data != null) {
                $("#fileId").val(data.id);
            }
            if (DOM.form.valid()) {
                DOM.form.submit();
            }
        });

        DOM.downloadFile.click(function () {
            var fileId = $("#fileId").val();
            FileUtil.download(fileId, function (rs) {

            });
        });
    }

    // var method = {
    //     deletePhoto1: deletePhoto1
    // }
    //
    // $.extend(Page, method);
    return Page;
});